using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting.Silverlight;

namespace mygestalt
{
	public static class PythonEngine
	{
		public static ScriptScope Run(string source)
		{
			var setup = Configuration.LoadFromAssemblies(Package.GetManifestAssemblies());
			setup.HostType = typeof(BrowserScriptHost);
			setup.DebugMode = true;
			var runtime = new ScriptRuntime(setup);
			var engine = runtime.GetEngine("IronPython");
			var scope = engine.CreateScope();
			const string init = @"
import clr
clr.AddReference('System.Windows.Browser')

from System.Windows.Browser import *

";

			ScriptSource initSource = engine.CreateScriptSourceFromString(init, SourceCodeKind.Statements);
			initSource.Execute(scope);
			var script = engine.CreateScriptSourceFromString(source, SourceCodeKind.Statements);
			script.Execute(scope);

			return scope;
		}
	}
}